package com.asset.inventory.viewModel

import android.graphics.pdf.PdfDocument
import androidx.lifecycle.MutableLiveData
import com.asset.inventory.base.BaseViewModel
import com.asset.inventory.constant.PageType
import com.asset.inventory.manager.ConfigInfoManager
import com.asset.inventory.model.ConfigInfo

/**
 * 页面名称：配置信息页面
 * 创建时间  2021/04/10 17:29
 */
class ConfigInfoViewModel: BaseViewModel(){

    var PAGE_TYPE = PageType.TYPE_DEPARTMENT

    private val configInfoList = mutableListOf<ConfigInfo>()

    private val configInfoLiveData = MutableLiveData<MutableList<ConfigInfo>>()

    fun observerConfigInfo() = configInfoLiveData

    fun getConfigInfoList(type: Int,code: String = ""){
        PAGE_TYPE = type
        when(type){
            PageType.TYPE_DEPARTMENT -> {
                val orgInfo = ConfigInfoManager.getOrgInfo()
                for(department in orgInfo){
                    val configInfo = ConfigInfo(department.name,department.code)
                    configInfoList.add(configInfo)
                }
            }

            PageType.TYPE_USER -> {
                val userInfo = ConfigInfoManager.getUserList(code)
                for(user in userInfo){
                    val configInfo = ConfigInfo(user.name,user.username)
                    configInfoList.add(configInfo)
                }
            }

            PageType.TYPE_LOCATION -> {
                val loacationInfo = ConfigInfoManager.getLocationInfo()
                for(location in loacationInfo){
                    val configInfo = ConfigInfo(location.name,location.code)
                    configInfoList.add(configInfo)
                }
            }
        }
        configInfoLiveData.postValue(configInfoList)
    }

}